import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

let userInfo= uni.getStorageSync('userInfo') || {};
let token= uni.getStorageSync('token') || '';
let listToken= uni.getStorageSync('listToken') || '';
let shortData = uni.getStorageSync('shortData') || {};
let Console = uni.getStorageSync('Console') || {};
const store=new Vuex.Store({
	state:{
		/*修改域名注意TradingView*/
		// baseUrl:'http://api.zhanl.live/',//正式环境
		baseUrl:'https://testapi.zhanl.live/',//本机
		// baseUrl:'http://testapi.zhanlang.info/',//本机
		 wsUrl:'ws://testapi.zhanl.live/ws',//本机
		// wsUrl:'ws://testapi.zhanlang.info/ws',/*首页24小时行情*/
		// wsUrl:'ws://api.zhanl.live/ws',/*首页24小时行情--修改域名*/
		version:'1.13',//当前版本
		userInfo:userInfo,//用户信息
		token:token,//token
		shortData:shortData,//临时数据
		Console:Console,/*控制台缓存数据*/
	},
	getters:{
		
	},
	mutations:{
		// 登录
		login(state,data){
			state.token=data.token;
			uni.setStorageSync('token',data.token)
		},
		
		// 登出
		logout(state){
			state.token='';
			uni.setStorageSync('token',state.token)
			state.userInfo='';
			uni.setStorageSync('userInfo',{})
		},
		// 存储更新个人信息
		updateUserInfo(state,data){
			state.userInfo=data;
			uni.setStorageSync('userInfo',data)
		},
		// 暂存公告详情数据
		saveNews(state,data){
			state.news=data;
		},
		// 存储临时数据
		saveShortData(state,data){
			state.shortData=data;
			uni.setStorageSync('shortData',state.shortData);
		},
		saveConsole(state,data){
			state.Console=data;
			uni.setStorageSync('Console',data);
		},
	},
	actions:{
		
	}
})
export default store;